home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / deviceuricombobox.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.2 KB  |  122 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from ui_utils import *
  6. from base import device
  7. from PyQt4.QtCore import *
  8. from PyQt4.QtGui import *
  9. DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY = 0
  10. DEVICEURICOMBOBOX_TYPE_FAX_ONLY = 1
  11. DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX = 2
  12.  
  13. class DeviceUriComboBox(QWidget):
  14.     
  15.     def __init__(self, parent):
  16.         QWidget.__init__(self, parent)
  17.         self.device_uri = ''
  18.         self.initial_device = None
  19.         self.updating = False
  20.         self.typ = DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY
  21.         self.filter = None
  22.         self.devices = None
  23.         self.initUi()
  24.  
  25.     
  26.     def initUi(self):
  27.         HBoxLayout = QHBoxLayout(self)
  28.         HBoxLayout.setObjectName('HBoxLayout')
  29.         self.NameLabel = QLabel(self)
  30.         self.NameLabel.setObjectName('NameLabel')
  31.         HBoxLayout.addWidget(self.NameLabel)
  32.         SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  33.         HBoxLayout.addItem(SpacerItem)
  34.         self.ComboBox = QComboBox(self)
  35.         sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  36.         sizePolicy.setHorizontalStretch(0)
  37.         sizePolicy.setVerticalStretch(0)
  38.         sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
  39.         self.ComboBox.setSizePolicy(sizePolicy)
  40.         self.ComboBox.setObjectName('ComboBox')
  41.         HBoxLayout.addWidget(self.ComboBox)
  42.         self.NameLabel.setText(self._DeviceUriComboBox__tr('Device:'))
  43.         self.connect(self.ComboBox, SIGNAL('currentIndexChanged(const QString &)'), self.ComboBox_currentIndexChanged)
  44.  
  45.     
  46.     def setType(self, typ):
  47.         if typ in (DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY, DEVICEURICOMBOBOX_TYPE_FAX_ONLY, DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX):
  48.             self.typ = typ
  49.         
  50.  
  51.     
  52.     def setFilter(self, filter):
  53.         self.filter = filter
  54.  
  55.     
  56.     def setInitialDevice(self, device_uri):
  57.         self.initial_device = device_uri
  58.  
  59.     
  60.     def setDevices(self):
  61.         if self.typ == DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY:
  62.             be_filter = [
  63.                 'hp']
  64.         elif self.typ == DEVICEURICOMBOBOX_TYPE_FAX_ONLY:
  65.             be_filter = [
  66.                 'hpfax']
  67.             self.NameLabel.setText(self._DeviceUriComboBox__tr('Fax Device:'))
  68.         else:
  69.             be_filter = [
  70.                 'hp',
  71.                 'hpfax']
  72.         self.devices = device.getSupportedCUPSDevices(be_filter, self.filter)
  73.         return len(self.devices)
  74.  
  75.     
  76.     def updateUi(self):
  77.         if self.devices is None:
  78.             self.setDevices()
  79.         
  80.         self.device_index = { }
  81.         if self.devices:
  82.             if self.initial_device is None:
  83.                 self.initial_device = user_conf.get('last_used', 'device_uri')
  84.             
  85.             self.updating = True
  86.             
  87.             try:
  88.                 k = 0
  89.                 for i, d in enumerate(self.devices):
  90.                     self.ComboBox.insertItem(i, d)
  91.                     if self.initial_device is not None and d == self.initial_device:
  92.                         self.initial_device = None
  93.                         k = i
  94.                         continue
  95.                 
  96.                 self.ComboBox.setCurrentIndex(-1)
  97.             finally:
  98.                 self.updating = False
  99.  
  100.             self.ComboBox.setCurrentIndex(k)
  101.             if len(self.devices) == 1:
  102.                 self.emit(SIGNAL('DeviceUriComboBox_oneDevice'))
  103.             
  104.         else:
  105.             self.emit(SIGNAL('DeviceUriComboBox_noDevices'))
  106.  
  107.     
  108.     def ComboBox_currentIndexChanged(self, t):
  109.         if self.updating:
  110.             return None
  111.         self.device_uri = unicode(t)
  112.         if self.device_uri:
  113.             user_conf.set('last_used', 'device_uri', self.device_uri)
  114.             self.emit(SIGNAL('DeviceUriComboBox_currentChanged'), self.device_uri)
  115.         
  116.  
  117.     
  118.     def __tr(self, s, c = None):
  119.         return qApp.translate('DeviceUriComboBox', s, c)
  120.  
  121.  
  122.